/*
 * 进入商场处理程序
*/

package net.sf.odinms.net.channel.handler;


import java.rmi.RemoteException;
import net.sf.odinms.client.MapleBuffStat;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.net.AbstractMaplePacketHandler;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.net.world.remote.WorldChannelInterface;
import net.sf.odinms.tools.HexTool;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;

/**
 *
 * @author Acrylic (Terry Han)
 */
public class EnterCashShopHandler extends AbstractMaplePacketHandler {
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(EnterCashShopHandler.class);
    @Override
    public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
       //  c.getPlayer().dropMessage(1, "由于系统错误，现在无法进入商场！");
       //  c.getSession().write(MaplePacketCreator.sendBlockedMessage(3));
       //   c.getSession().write(MaplePacketCreator.enableActions());
        if (c.getChannelServer().allowCashshop()) {
            if (c.getPlayer().getBuffedValue(MapleBuffStat.SUMMON) != null) {
                c.getPlayer().cancelEffectFromBuffStat(MapleBuffStat.SUMMON);
                if(c.getPlayer().getSkillLevel(1320009) > 0) {
                    for(int i = 0; i < 5 ; i++)
                        c.getSession().write(MaplePacketCreator.cancelBuff(null, c.getPlayer(), 2022125 + i));
                }
            }
            try {
                WorldChannelInterface wci = ChannelServer.getInstance(c.getChannel()).getWorldInterface();
                wci.addBuffsToStorage(c.getPlayer().getId(), c.getPlayer().getAllBuffs());
            } catch (RemoteException e) {
                c.getChannelServer().reconnectWorld();
            }
            c.getPlayer().getMap().removePlayer(c.getPlayer());
            c.getPlayer().setInCS(true);
            c.getSession().write(MaplePacketCreator.warpCS1(c, false));
            c.getSession().write(MaplePacketCreator.warpCS2(c, false));
            c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.getCSInventory(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.getCSGifts(c.getPlayer()));
            /*
            c.getSession().write(MaplePacketCreator.cs_look());
            c.getSession().write(MaplePacketCreator.cs_MLS());
            c.getSession().write(MaplePacketCreator.sendWishList(c.getPlayer().getId()));
            c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.getCSInventory(c.getPlayer()));
            c.getSession().write(MaplePacketCreator.getCSGifts(c.getPlayer()));
            */
            c.getPlayer().saveToDB(true);
        } else {
            c.getSession().write(MaplePacketCreator.sendBlockedMessage(3));
            c.getSession().write(MaplePacketCreator.enableActions());
        }
  
    }

}